<template>
  <div class="expression-add">
    <el-dialog
        :visible.sync="centerDialogVisible"
        width="30%"
        top="25vh"
        center>
      <span>需要注意的是内容是默认不居中的</span>
      <span slot="footer" class="dialog-footer">
      <el-button type="primary" @click="centerDialogVisible = false">{{ addOrEdit ? '新增' : '修改' }}</el-button>
      <el-button @click="centerDialogVisible = false">取 消</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
export default {
  name: "index",
  props: {
    show: {
      type: Boolean,
      require: true,
      default() {
        return false;
      }
    },
    expressionModel: {
      type: Object,
      require: true,
      default() {
        return {};
      },
    }
  },
  data() {
    return {
      centerDialogVisible: false,
      formModel: {},
      addOrEdit: true
    }
  },
  watch: {
    //监听父组件传递的值
    show(newValue) {
      if (newValue) {
        this.centerDialogVisible = newValue
      }
    },
    //回调值
    centerDialogVisible(newValue) {
      if (!newValue) {
        this.$emit('closeChild', this.centerDialogVisible)
      }
    },
    //传递对象
    expressionModel(newValue) {
      //修改
      if (JSON.stringify(newValue) !== '{}') {
        this.addOrEdit = false
      }
      //新增
      else {
        this.addOrEdit = true
      }
    }
  }
}
</script>

<style scoped lang="scss">

</style>